<template>
    <div class="app-container">
      <el-row :gutter="20">
          
          <el-col :span="4" :xs="24">
            <div class="head-container">
              <el-input v-model="cateName" placeholder="请输入流程分类名" clearable size="small" prefix-icon="el-icon-search" style="margin-bottom: 20px" />
            </div>
            <div class="head-container">
              <el-tree :data="data" :props="defaultProps" :expand-on-click-node="false" :filter-node-method="filterNode"  ref="tree" default-expand-all @node-click="handleNodeClick" />
            </div>
          </el-col>
          <el-col :span="20" :xs="24">
              <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
                <el-form-item label="流程名称" prop="deptName">
                  <el-input
                    v-model="queryParams.processDefinitionName"
                    placeholder="请输入流程名称"
                    clearable
                    size="small"
                    @keyup.enter.native="handleQuery"
                  />
                </el-form-item>
                <el-form-item>
                  <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                  <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                </el-form-item>
              </el-form>
              <el-row>
              <el-col :span="8" v-for="row in list" style="height:200px;">
                  <div class="filter-container" style="margin-right: 3px;margin-bottom: 3px;">
                      <el-card style="height:180px;">
                          <div slot="header" class="clearfix">
                              <span>{{row.name}}-v{{row.version}}</span>
                             
                          </div>
                          <div class="text">
                              描述:{{row.description?row.description:'无描述'}}
                          </div>
                          <div class="text" >
                              分类:{{row.category?row.category:'无分类'}}
                          </div>
                          <div style="position: relative;text-align: right;margin-top:30px;">
                              <el-button  size="mini" @click="btnImage(row.id)">流程图</el-button>
                              <el-button  v-hasPermi="['flowable:process:renderedStartForm']" size="mini" @click="btnStartInstance(row)">发起流程
                              </el-button>
                          </div>
                      </el-card>
                  </div>
              </el-col>
              </el-row>
              <pagination
                  v-show="total>0"
                  :total="total"
                  :page.sync="queryParams.pageNum"
                  :limit.sync="queryParams.pageSize"
                  @pagination="getList"
                />
          </el-col>
       </el-row>

      
        <el-dialog title="流程图" fullscreen :visible.sync="dialogImageVisible" width="80%">
            <img :src="imagePath" alt="流程图">
        </el-dialog>
        <start-process v-if="dialogStartInstanceVisible" :visible.sync="dialogStartInstanceVisible"
        :processDefinition="processDefinition"></start-process>

    </div>
</template>
<script>
import { getMyList } from "@/api/flowable/process";
import StartProcess from "../components/StartProcess";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
    name: 'FlowableStartMyProcess',
    components: {StartProcess,Treeselect},
    data() {
      return {
        cateName:undefined,
        data: [],
        defaultProps: {
          children: "children",
          label: "label",
        },
        cateOptions:[],
        processDefinition: undefined,
        dialogStartInstanceVisible:false,
        imagePath:"",
        dialogImageVisible:false,
        // 遮罩层
        loading: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 角色表格数据
        list: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          processDefinitionName:undefined,
          processDefinitionCategory:undefined
        },

      }
    },
    watch: {
      cateName(val) {
        this.$refs.tree.filter(val);
      },
    },
    created() {
      var that=this;
      this.getList();
      this.getDicts("model_cate").then((response) => {
        this.cateOptions = response.data;
        this.cateOptions.forEach(function(item,index,arr){
            var item={label: item.dictLabel,value:item.dictValue};
            that.data.push(item);
        })
      });
        
    },
    methods: {
      filterNode(value, data) {
        if (!value) return true;
        return data.label.indexOf(value) !== -1;
      },
      handleNodeClick(data) {
        this.queryParams.processDefinitionCategory=data.value;
        this.queryParams.pageNum = 1;
        this.getList();
      },
      getList(){
        this.loading = true;
        getMyList(this.queryParams,).then(
          response => {
            this.list = response.rows;
            this.total = response.total;
            this.loading = false;
          }
        );

      },
       /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      btnImage(processDefinitionId) {
          this.imagePath = `${process.env.VUE_APP_BASE_API}` + '/flowable/process/image?processDefinitionId=' + processDefinitionId  + '&time=' + new Date()
          this.dialogImageVisible = true
      },
      btnStartInstance(row) {
          this.processDefinition = row
          this.dialogStartInstanceVisible = true
      }
       
    }
}
</script>
<style>
.text{
  color: rgb(104, 104, 104);
  font-size: 14px;
}
</style>
